<?php # Page Content - calendar.php
// get the name of the page you came from to this module and save it
	if (array_key_exists('HTTP_REFERER', $_SERVER)) {
		$RefererNameArray = split('[\/\\\.]',$_SERVER['HTTP_REFERER']);
		$RefererName = $RefererNameArray[sizeof($RefererNameArray) - 2];
		if ($RefererName != "calendar") {
			$originalHTTP_REFERER = $_SERVER['HTTP_REFERER'];
		}
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<!-- begin header template (+ 3 lines up!) -->
<head>
<title>WIKINDX</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
#calendarTable {
	border: 1px solid black ;
	margin-right: auto;
	margin-left: auto;
}
#calendarHeaderTable {
	width: 100%;
}
#calendarTableHeader {
	background-color: rgb(200,200,220);
}
.calendarTableCell {
	font: bold 12px/12px Verdana, Arial, Sans-Serif;
	width: 20;
	text-align: right;
}
.calendarTableIndexCell {
	width: 20px;
}
</style>
<!--
<link rel="stylesheet" href="../../../templates/classic/classic.css" type="text/css" />
-->
<SCRIPT TYPE="text/javascript">
<!--  thanks to Miko O'Sullivan at http://www.faqs.org/docs/htmltut/linking/linking_famsupp_75.html
function targetopener(dateString) {
//	window.opener.focus();
	window.opener.insertDateStringRte(dateString);
	window.close();
}
//-->
</SCRIPT>
</head>
<body>
<?php
$m = $y = FALSE;
if (array_key_exists('m', $_GET)) {
	$m = $_GET['m'];
}

if (array_key_exists('y', $_GET)) {
	$y = $_GET['y'];
}

mk_drawCalendar($m, $y);
//*********************************************************
// DRAW CALENDAR
// calendar modified from code by  web blazonry
//*********************************************************
/*
    Draws out a calendar (in html) of the month/year
    passed to it date passed in format mm-dd-yyyy 
*/
function mk_drawCalendar($m,$y)
{
    if ((!$m) || (!$y))
    { 
        $m = date("m",mktime());
        $y = date("Y",mktime());
    }

    /*== get what weekday the first is on ==*/
    $tmpd = getdate(mktime(0,0,0,$m,1,$y));
    $month = $tmpd["month"]; 
    $firstwday= $tmpd["wday"];

    $lastday = mk_getLastDayofMonth($m,$y);
		global $originalHTTP_REFERER;

?>
<table id="calendarTable">
<tr><td colspan=7 id="calendarTableHeader">
    <table cellpadding=0 cellspacing=0 border=0 id="calendarHeaderTable">
    <tr><th class="calendarTableIndexCell"><a onFocus='blur()' class='link' href="<?$_SERVER['PHP_SELF']?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y; ?>">&lt;&lt;</a></th>
    <th><font size=2><?="$month $y"?></font></th>
    <th class="calendarTableIndexCell"><a onFocus='blur()' class='link' href="<?$_SERVER['PHP_SELF']?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y; ?>">&gt;&gt;</a></th>
    </tr></table>
</td></tr>
<tr><th class="calendarTableCell">Su</th><th class="calendarTableCell">M</th>
    <th class="calendarTableCell">T </th><th class="calendarTableCell">W</th>
    <th class="calendarTableCell">Th</th><th class="calendarTableCell">F</th>
    <th class="calendarTableCell">Sa</th></tr>
<?  $d = 1;
    $wday = $firstwday;
    $firstweek = true;

    /*== loop through all the days of the month ==*/
    while ( $d <= $lastday) 
    {

        /*== set up blank days for first week ==*/
        if ($firstweek) {
            echo "<tr>";
            for ($i=1; $i<=$firstwday; $i++) 
            { echo "<td><font size=2>&nbsp;</font></td>"; }
            $firstweek = false;
        }

        /*== Sunday start week with <tr> ==*/
        if ($wday==0) { echo "<tr>"; }

        /*== check for event ==*/  
        echo "<td class='calendarTableCell'>";
				echo "<a onFocus='blur()' class='link' href='' onClick='targetopener(\"" . $y . "-" . sprintf('%02d',$m) . "-" . sprintf('%02d',$d) . "\")'>" . sprintf('%02d',$d) . "</a>";
        echo "</td>\n";

        /*== Saturday end week with </tr> ==*/
        if ($wday==6) { echo "</tr>\n"; }

        $wday++;
        $wday = $wday % 7;
        $d++;
    }
?>
</tr></table>
<br>

<?
/*== end drawCalendar function ==*/
} 

/*== get the last day of the month ==*/
function mk_getLastDayofMonth($mon,$year)
{
    for ($tday=28; $tday <= 31; $tday++) 
    {
        $tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
        if ($tdate["mon"] != $mon) 
        { break; }

    }
    $tday--;

    return $tday;
}
?>
</body>
</html>
